﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading.Tasks;

namespace Civilisation_code.PVCarte
{
    /// <summary>
    /// Poids-mouche pour la construction des images de ressources
    /// Singleton
    /// </summary>
    class Fabrique_Img_Ressource
    {
        /// <summary>
        /// Instance de la classe 
        /// Singleton
        /// </summary>
        public static readonly Fabrique_Img_Ressource FABRIQUE_IMG_RESSOURCE = new Fabrique_Img_Ressource();

        /// <summary>
        /// Hastables contenant tous les ImageBrush
        /// </summary>
        private Hashtable instances;

        /// <summary>
        /// Constructeur privé
        /// </summary>
        private Fabrique_Img_Ressource()
        {
            instances = new Hashtable();
        }

        /// <summary>
        /// Méthode permettant d'obtenir l'ImageBrush correspondant aux ressources
        /// </summary>
        /// <param name="nom_ressource">Nom de la ressource</param>
        /// <param name="bonus">Nom du bonus</param>
        /// <returns>L'ImageBrush correspondant</returns>
        public ImageBrush obtenirRessource(string nom_ressource, string bonus)
        {
            if (!instances.ContainsKey(nom_ressource + bonus))
            {
                creationRessource(nom_ressource + bonus);
            }
            return (ImageBrush)instances[nom_ressource + bonus];
        }

        /// <summary>
        /// Création de l'ImageBrush
        /// </summary>
        /// <param name="nom_ressource">Nom de la ressource + bonus</param>
        void creationRessource(string nom_ressource)
        {
            ImageBrush im = new ImageBrush();
            switch (nom_ressource)
            {
                case "Montagne" :
                    im.ImageSource = (System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(Civilisation.Properties.Resources.montagne.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()));
                    instances.Add(nom_ressource,im);
                    break;
                case "MontagneFer":
                    im.ImageSource = (System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(Civilisation.Properties.Resources.montagneFer.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()));
                    instances.Add(nom_ressource, im);
                    break;
                case "MontagneFruit":
                    im.ImageSource = (System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(Civilisation.Properties.Resources.montagneFruit.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()));
                    instances.Add(nom_ressource, im);
                    break;
                case "Plaine":
                    im.ImageSource = (System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(Civilisation.Properties.Resources.plaine.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()));
                    instances.Add(nom_ressource, im);
                    break;
                case "PlaineFer":
                    im.ImageSource = (System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(Civilisation.Properties.Resources.plaineFer.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()));
                    instances.Add(nom_ressource, im);
                    break;
                case "PlaineFruit":
                    im.ImageSource = (System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(Civilisation.Properties.Resources.plaineFruit.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()));
                    instances.Add(nom_ressource, im);
                    break;
                case "Desert":
                    im.ImageSource = (System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(Civilisation.Properties.Resources.desert.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()));
                    instances.Add(nom_ressource, im);
                    break;
                case "DesertFer":
                    im.ImageSource = (System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(Civilisation.Properties.Resources.desertFer.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()));
                    instances.Add(nom_ressource, im);
                    break;
                case "DesertFruit":
                    im.ImageSource = (System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(Civilisation.Properties.Resources.desertFruit.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()));
                    instances.Add(nom_ressource, im);
                    break;
            }
        }
    }
}

